{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Discrete Bayes Animations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <style>\n",
       "        .output_wrapper, .output {\n",
       "            height:auto !important;\n",
       "            max-height:100000px;\n",
       "        }\n",
       "        .output_scroll {\n",
       "            box-shadow:none !important;\n",
       "            webkit-box-shadow:none !important;\n",
       "        }\n",
       "        </style>\n",
       "    "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import sys\n",
    "sys.path.insert(0,'..') # allow us to format the book\n",
    "import book_format\n",
    "book_format.set_style()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook creates the animations for the Discrete Bayesian filters chapter. It is not really intended to be a readable part of the book, but of course you are free to look at the source code, and even modify it. However, if you are interested in running your own animations, I'll point you to the examples subdirectory of the book, which contains a number of python scripts that you can run and modify from an IDE or the command line. This module saves the animations to GIF files, which is quite slow and not very interactive. \n",
    "\n",
    "On Windows you need to install ffmpeg with\n",
    "\n",
    "    $ conda install -c conda-forge ffmpeg\n",
    "    \n",
    "I don't know what to do for linux or MaxOS."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import animation\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from kf_book.book_plots import bar_plot\n",
    "%matplotlib inline\n",
    "\n",
    "# the predict algorithm of the discrete bayesian filter\n",
    "def predict(pos, move, p_correct, p_under, p_over):\n",
    "    n = len(pos)\n",
    "    result = np.array(pos, dtype=float)\n",
    "    for i in range(n):\n",
    "                result[i] =  \\\n",
    "            pos[(i-move) % n]   * p_correct + \\\n",
    "            pos[(i-move-1) % n] * p_over + \\\n",
    "            pos[(i-move+1) % n] * p_under          \n",
    "    return result\n",
    "\n",
    "\n",
    "def normalize(p):\n",
    "    s = sum(p)\n",
    "    for i in range (len(p)):\n",
    "        p[i] = p[i] / s\n",
    "        \n",
    "# the update algorithm of the discrete bayesian filter\n",
    "def update(pos, measure, p_hit, p_miss):\n",
    "    q = np.array(pos, dtype=float)\n",
    "    for i in range(len(hallway)):\n",
    "        if hallway[i] == measure:\n",
    "            q[i] = pos[i] * p_hit\n",
    "        else:\n",
    "            q[i] = pos[i] * p_miss\n",
    "    normalize(q)\n",
    "    return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'ffmpeg'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import matplotlib\n",
    "# make sure our matplotlibrc has been edited to use imagemagick\n",
    "print(matplotlib.matplotlib_fname())\n",
    "matplotlib.rcParams['animation.writer']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEICAYAAABPgw/pAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAARNUlEQVR4nO3df6zddX3H8efLlo7flkl12NaJWQWrQcAr4lTGZGqrRnQxBnQw2FhHAk6dyWAmaozJoonbiBNtKjLwF8QfODvWiTqHxjkct4LQimAFhGtBykBAMGLhvT/Ot+5wub3nUM899X54PpKTnu/3+7nn/T7t7et+7uec7/ekqpAkzX9P2N0NSJJGw0CXpEYY6JLUCANdkhphoEtSIwx0SWqEgS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WAJPsk2W/HfeDl9H4tn3NVdTtwa5JDul3H8chLXI/DiYxxuaVzC3B0kr277/nj6L1eNBZJntz9+TTgjxn/83+Epj8kunZy2YJx1U9yEXAscGCSKeDdVfWxMZV/EXAScG23lg3wjqraMIbaBwEXdh+O8gTgM1U19rcQ7gZPAb7QyxUWAp+uqi+Nsf6bgU91k5cbGeMlOLo15JcBfzmumgBV9e0knwO+Q2+54yrGeyr+55M8CfglcEZV3T3G2o/iqf+S1IjWl1wk6XHDQJekRhjoktQIA12SGmGgS1IjDHRJaoSBLkmN+D813WlzoLZHIQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAC3CAYAAAA8YQj2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAP9ElEQVR4nO3df6xfdX3H8efL1k4BFSKFYVtGl1WgEkG8ok5FHFNbJXYas1AdqFnWYcCgM5nMRI0xWWKimzGiTQcMnA6mgFtlHejihDmH4xYRqBWsVeFSkDJABI1YeO+P78F8d72399vD936/B+7zkdz0nnM+93te9/b2vu75nB9NVSFJ0r56yrgDSJKemCwQSVIrFogkqRULRJLUigUiSWrFApEktWKBSJJasUC04CR5eZJvJvlpknuT/FeSFzXb3p7kG/O4721JHux725Pky33bK8lDfdvPm68s0uO1eNwBpFFK8kzgCuCdwBeAJcArgF+OYv9V9by+LAF+AHxx2rBjq2rHKPJIj4dHIFpongtQVRdX1SNV9Yuq+kpV3ZjkaGAj8NLmt//7AZL8VpKPJbktyU+SbEzy9GbbSUmmkrw/yT1JfpTkrQNmORE4BLhs+J+mNP8sEC00twKPJLkoydokBz22oaq2A2cA/11VB1TVgc2mj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7i5dV1fH0nm59ZjPdOWqLgeOBz1TVC4CHgHGdL1wCvAH44pj2fxC9WYqVwHOA/ZP8ySgzVNV24KPAV+lNX30H2DPKDHuzkApkoMetLBTNOYfLgM9X1eXjztNMk3wdWDPiXb8MeENz/uES4A+SfG7EGQCoql3Nn3cDX6I37TpqU8BU35HgpfQKZRzWAtdX1U/GtP8/BH5YVbur6lfA5cDvjzpEVZ1fVcdX1Yn0pr87cf4DFlaBDPJIlgWhOXl9PrC9qv5mjDmWJjmwef/p9P7Bfm+UGarqr6pqeVUdQe974mtVNdLfMgGS7N9c0EAzZfQaetMXI1VVdwG3JzmyWXUyMNKLK/qsZ0zTV43bgJck2a/5N3MyvfOFI5XkkObPw4E3Md6vyf8z0J3oTwazPZJl1DmSXAycBBycZAr4UFWdP+IYLwNOA25qzj8AvL954sAoHQZc1Fxp8xTgC1U1tstox+xQ4Eu9n1MsBv6xqq4cU5Z3AZ9vftHayRgeTdTM978a+PNR7/sxVfWtJJcC19ObNvo247kb/LIkzwZ+BZxZVfeNIcOMFsxlvJKk4VpIU1iSpCGyQCRJrVggkqRWLBBJUisWiCSpFQtEktSKBSJJasUCkSS18n+Iw9au1ju80wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 468x180 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from kf_book.gif_animate import animate\n",
    "\n",
    "pos = [1.0,0,0,0,0,0,0,0,0,0]\n",
    "def bar_animate(nframe):\n",
    "    global pos\n",
    "    plt.cla()\n",
    "    bar_plot(pos)\n",
    "    plt.title('Step {}'.format(nframe + 1))\n",
    "    pos = predict(pos, 1, .8, .1, .1)\n",
    "\n",
    "for i in range(10):\n",
    "    bar_animate(i)\n",
    "\n",
    "fig = plt.figure(figsize=(6.5, 2.5))\n",
    "animate('02_no_info.gif', bar_animate, fig=fig, frames=75, interval=75);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"02_no_info.gif\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAC3CAYAAAA8YQj2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQL0lEQVR4nO3df5BddX3G8ffjRqoEMCirhSRUOo1gdBBxDVqVUqmaqGO002lBK9XWpnTAX3WmUmfUcZzpDKNtKRXNpIBgtWRUsKY2inYsWmuhSQCREMEUFdaAhIL8dIyBT/+4B+d63WRvDnfvvWTfr5md7Dnnu/c8uyz77PmeH5uqQpKkffW4UQeQJD02WSCSpFYsEElSKxaIJKkVC0SS1IoFIklqxQKRJLVigWjeSfLiJN9Mck+Su5L8V5LnN9velOQbQ8jw5CQ7e/eV5LgkW5I82Px73FxnkdqyQDSvJDkE+ALwD8CTgcXAB4CfDjnK2cC2nmwHAJ8HPgkcClwMfL5ZL40dC0TzzTMAquqSqnqoqn5SVV+uquuSPBNYC7wwyf1JfgyQ5FeSfDjJLUl+lGRtkic2205KMp3kPUnuTPL9JG/YW4AkLwSeDXy8Z9NJwALgnKr6aVWdCwR46QA/f2lgLBDNNzcBDyW5OMmqJIc+sqGqtgGnA/9dVQdV1aJm09l0iuc44DfoHLW8r+s1fxU4rFn/R8C6JEfPtPMkE8B5wJlA73OEngVcV7/4fKHrmvXS2LFANK9U1b3Ai+n88P5HYGeSDUmeNtP4JAH+FHhnVd1VVfcBfw2c0jP0vc1Rw9eAfwN+fw8R3gZcVVVbZth2EHBPz7p7gIP7+NSkoVsw6gDSsDVHGm8CSHIMnXMO5wCnzjB8EjgQ2NLpEqAzrTTRNebuqnqga/kHwBG9L5TkCDoF8rw9RLsfOKRn3SHAfXv8ZKQR8ghE81pVfQe4iM45CfjlaaU7gZ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8MOUVUXVNXxVXUinenvsTj/AfOrQPp5JMu80Jy8vgDYVlV/O8Ick0kWNe8/kc7/sN8ZZoaq+quqWlJVT6fzPfHVqhrqb5kASRY2FzTQTBm9nM70xVBV1e3ArUmObladDAz14ooupzKi6avGLcALkhzY/D9zMp3zhUOV5KnNv0cCv8tovya/oK870fcHe3oky7BzJLkEOAk4LMk08P6qumDIMV4EvBH4dnP+AeA9zRMHhulw4OLmSpvHAZ+uqpFdRjtiTwM+1/k5xQLgn6vqSyPK8lbgU80vWjczgkcTNfP9LwP+bNj7fkRVXZXks8DVdKaNrmE0d4NfmuQpwM+AM6rq7hFkmNG8uYxXkjRY82kKS5I0QBaIJKkVC0SS1IoFIklqxQKRJLVigUiSWrFAJEmtWCCSpFb+H5Ly4ep1xxPHAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 468x180 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pos = np.array([.1]*10)\n",
    "hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])\n",
    "\n",
    "def bar_animate(nframe):\n",
    "    global pos\n",
    "    #if nframe == 0:\n",
    "    #   return\n",
    "\n",
    "    bar_plot(pos, ylim=(0,1.0))\n",
    "    plt.title('Step {}'.format(nframe + 1))\n",
    "    if nframe % 2 == 0:\n",
    "        pos = predict(pos, 1, .9, .05, .05)\n",
    "    else:\n",
    "        x = int((nframe/2) % len(hallway))\n",
    "        z = hallway[x]\n",
    "        pos = update(pos, z, .9, .2)\n",
    "        \n",
    "\n",
    "fig = plt.figure(figsize=(6.5, 2.5))\n",
    "animate('02_simulate.gif', bar_animate, fig=fig, frames=40, interval=85);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " <img src=\"02_simulate.gif\">"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
